package com.example.helloworld;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast;
import android.widget.ToggleButton;

public class SwitchActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
    private ToggleButton toggleButton;
    private Switch aSwitch;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_switch);
        toggleButton = findViewById(R.id.tbtn_open);
        aSwitch = findViewById(R.id.swh_status);

        toggleButton.setOnCheckedChangeListener(this);
        aSwitch.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if(isChecked){
            Toast.makeText(this,"选中了",Toast.LENGTH_SHORT).show();
        }else {
            Toast.makeText(this,"没有选中",Toast.LENGTH_SHORT).show();
        }
    }
}